<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('提出人')" prop="proposer">
            <el-input v-model="form.proposer" :placeholder="$t('提出人')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('诉求说明')" prop="description">
            <el-input v-model="form.description" type="textarea" :placeholder="$t('诉求说明')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('诉求反馈')" prop="feedback">
            <el-input v-model="form.feedback" type="textarea" :placeholder="$t('诉求反馈')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 填报段需求.  72732 -->
      <FileTable
        v-if="form.fileList !== null && form.fileList !== undefined && form.fileList.length > 0"
        :list.sync="form.fileList"
        data-type="deal_enterprise_appeal"
        :business-id="autoBusinessId($route.query.id, form)"
        :btn-show="!otherBtnHide"
      />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存，保存并启动流程，取消 三个按钮-->
      <el-button @click="cancel">{{ $t("取消") }}</el-button>
      <el-button v-hasPermi="['deal:enterpriseAppeal:edit']" type="primary" @click="submitForm">{{ $t("保存") }}</el-button>
    </div>
  </div>
</template>

<script>
    import { saveDealEnterpriseAppeal, getDealEnterpriseAppeal } from '@/api/deal/enterpriseAppeal/dealEnterpriseAppeal'
    export default {
        data() {
            return {
                // 表单参数
                form: {
                  fileList: []
                },
                // 遮罩层
                loading: false,
                otherBtnHide: false,
                // 表单校验
                rules: {
                  proposer: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  description: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
                }
            }
        },
        created() {
        },
        methods: {
            // 初始化数据
            init(data) {
                if (data !== null && data.id !== undefined) {
                    getDealEnterpriseAppeal(data.id).then(response => {
                        this.form = response.data
                    })
                } else {
                    this.reset()
                }
            },
            // 表单重置
            reset() {
                this.form = {
                id: undefined,
                companyId: this.$route.query.companyId,
                proposer: undefined,
                description: undefined,
                feedback: undefined,
                createBy: undefined,
                updateBy: undefined,
                createTime: undefined,
                updateTime: undefined,
                delFlag: undefined,
                fileList: []
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                this.$parent.$parent.formOpen = false
                // 刷新list页面
                this.$parent.$parent.getList()
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveDealEnterpriseAppeal(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                      this.locationError(document)
                    }
                })
           }

        }

    }
</script>
